<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="../error.jsp"%>

<%@page import="java.sql.Types"%>
<%@page import="df.jsp.Guard"%>
<%@page import="df.jsp.LabelMap"%>
<%@page import="df.jsp.Util"%>
<%@page import="df.bean.db.DBMgr"%>
<%@page import="df.bean.db.DataRecord"%>
<%@page import="df.bean.obj.util.JDate"%>

<%@ include file="../../_global.jsp" %>

<%
            //
            // Verify permission
            //

            if (!Guard.checkPermission(session, Guard.PAGE_INPUT_METHOD_ALLOC_MASTER_DETAIL)) {
                response.sendRedirect("../message.jsp");
                return;
            }

            //
            // Initial LabelMap
            //

            if (session.getAttribute("LANG_CODE") == null) {
                session.setAttribute("LANG_CODE", LabelMap.LANG_EN);
            }
            LabelMap labelMap = new LabelMap(session.getAttribute("LANG_CODE").toString());
            labelMap.add("TITLE_MAIN", "Payor Allocate Details", "รายการเงื่อนไขคู่สัญญา");
            labelMap.add("ADMISSION_TYPE_CODE", "Admission Type", "รหัส");
            labelMap.add("ORDER_ITEM_CODE", "Order Item Code", "รายการรักษา");
            labelMap.add("ORDER_ITEM_CATEGORY_CODE", "Order Item Category Code ", "กลุ่มรายการรักษา");
            labelMap.add("DOCTOR_TREATMENT_CODE", "Doctor treatment", "แพทย์ทำการ");
            labelMap.add("PAYOR_OFFICE_CODE", "Payor Offfice Code", "รหัสคู่สัญญา");
            labelMap.add("PRICE", "Price", "ราคา");
            labelMap.add("TAX_TYPE_CODE", "Tax type", "ประเภทภาษี");
            labelMap.add("EXCLUDE_TREATMENT", "Exclude treatment", "Exclude treatment");
            labelMap.add("EXCLUDE_TREATMENT_0", "ไม่นำไปรวมคิดขั้นบันได", "ไม่นำไปรวมคิดขั้นบันได");
            labelMap.add("EXCLUDE_TREATMENT_1", "นำไปรวมคิดขั้นบันได", "นำไปรวมคิดขั้นบันได");
			labelMap.add("NORMAL_ALLOCATE_PCT", "Normal Allocate", "ส่วนแบ่งแพทย์");
            labelMap.add("NORMAL_ALLOCATE_AMT", "Allocate Amount", "ราคาส่วนแบ่งแพทย์");
            labelMap.add("GUARANTEE_METHOD", "Revenue for Guarantee", "รายได้เพื่อเทียบการันตี");
            labelMap.add("GUARANTEE_SOURCE_AT", "DF After Allocate", "จำนวนเงินหลังแบ่ง");
            labelMap.add("GUARANTEE_SOURCE_BF", "DF Before Allocate", "จำนวนเงินก่อนแบ่ง");
            labelMap.add("REMARK", "Remark", "หมายเหตุ");
            labelMap.add("DOCTOR_CODE", "Doctor Code", "รหัสแพทย์");
            labelMap.add("IS_PRIVATE", "Doctor Private", "Doctor Private");
            labelMap.add("IS_PRIVATE_0", "None", "None");
            labelMap.add("IS_PRIVATE_1", "Private", "Private");
            labelMap.add("DOCTOR_CATEGORY_CODE", "Doctor Category Code", "กลุ่มแพทย์");
            labelMap.add("IS_ALLOC_FULL_TAX", "Revenue for Tax", "รายได้นำไปคิดภาษี");
            labelMap.add("IS_ALLOC_FULL_TAX_0", "After Allocate", "รายได้หลังแบ่ง");
            labelMap.add("IS_ALLOC_FULL_TAX_1", "Before Allocate", "รายได้ก่อนแบ่ง");
            labelMap.add("IS_ALLOC_FULL_TAX_2", "--- Undefined ---", "ไม่กำหนด");
            labelMap.add("BAHT"," Baht"," บาท");
            labelMap.add("PERCENT"," (xx.xxxx%)"," (xx.xxxx%)");
            labelMap.add("TAX_RATE", "Tax Rate", "Tax Rate");
            labelMap.add("TAX_RATE_0", "1", "1");
            labelMap.add("TAX_RATE_1", "1.1111", "1.1111");
            labelMap.add("TAX_RATE_2", "1.2500", "1.2500");
            
            //labelMap.add("ACTIVE", "Status", "สถานะ");
            //labelMap.add("ACTIVE_0", "Inactive", "ไม่ใช้งาน");
            //labelMap.add("ACTIVE_1", "Active", "ใช้งาน");
            request.setAttribute("labelMap", labelMap.getHashMap());
            
            //
            // Process request
            //

            request.setCharacterEncoding("UTF-8");
            byte MODE = DBMgr.MODE_INSERT;
            DataRecord methodRec = null, doctorCategoryRec = null, orderItemRec = null, orderItemCategoryRec = null,doctorCategoryDetailRec=null;
            
            String table = "STP_METHOD_ALLOC_PAYOR";
            
            if (request.getParameter("MODE") != null) {
                // Insert or update
                MODE = Byte.parseByte(request.getParameter("MODE"));
				

                methodRec = new DataRecord(table);

                methodRec.addField("HOSPITAL_CODE", Types.VARCHAR, session.getAttribute("HOSPITAL_CODE").toString(), true);//primary key
                methodRec.addField("ADMISSION_TYPE_CODE", Types.VARCHAR, request.getParameter("ADMISSION_TYPE_CODE"), true);//primary key
                methodRec.addField("DOCTOR_CATEGORY_CODE", Types.VARCHAR, request.getParameter("DOCTOR_CATEGORY_CODE"), true);//primary key
                methodRec.addField("DOCTOR_TREATMENT_CODE", Types.VARCHAR, request.getParameter("DOCTOR_TREATMENT_CODE"), true);//primary key
                methodRec.addField("PAYOR_OFFICE_CODE", Types.VARCHAR, request.getParameter("PAYOR_OFFICE_CODE"), true);//primary key
                methodRec.addField("ORDER_ITEM_CODE", Types.VARCHAR, request.getParameter("ORDER_ITEM_CODE"), true);//primary key
                methodRec.addField("ORDER_ITEM_CATEGORY_CODE", Types.VARCHAR, request.getParameter("ORDER_ITEM_CATEGORY_CODE"), true);//primary key
                methodRec.addField("PRICE", Types.NUMERIC, "0");
                methodRec.addField("IS_PRIVATE", Types.VARCHAR, request.getParameter("IS_PRIVATE"),true);//primary key
                methodRec.addField("TAX_TYPE_CODE", Types.VARCHAR, request.getParameter("TAX_TYPE_CODE"));
                methodRec.addField("EXCLUDE_TREATMENT", Types.VARCHAR, "Y");
                methodRec.addField("NORMAL_ALLOCATE_PCT", Types.NUMERIC, request.getParameter("NORMAL_ALLOCATE_PCT"));//primary key
                methodRec.addField("NORMAL_ALLOCATE_AMT", Types.NUMERIC, request.getParameter("NORMAL_ALLOCATE_AMT"));//primary key
                methodRec.addField("REMARK", Types.VARCHAR, request.getParameter("REMARK"));
                methodRec.addField("ACTIVE", Types.VARCHAR, request.getParameter("ACTIVE"));
                methodRec.addField("UPDATE_DATE", Types.VARCHAR, JDate.getDate());
                methodRec.addField("UPDATE_TIME", Types.VARCHAR, JDate.getTime());
                methodRec.addField("USER_ID", Types.VARCHAR, session.getAttribute("USER_ID").toString());
                methodRec.addField("IS_ALLOC_FULL_TAX", Types.VARCHAR, request.getParameter("IS_ALLOC_FULL_TAX").toString());
                methodRec.addField("TAX_RATE", Types.NUMERIC, request.getParameter("TAX_RATE").toString());
                methodRec.addField("GUARANTEE_SOURCE", Types.VARCHAR, request.getParameter("GUARANTEE_METHOD"));
                
                if (MODE == DBMgr.MODE_INSERT) {
                    if (DBMgr.insertRecord(methodRec)) {
                        session.setAttribute("MSG", labelMap.get(LabelMap.MSG_SAVE_SUCCESS).replace("[HREF]", "input/method_alloc_payor_main.jsp?PAYOR_OFFICE_CODE=" + methodRec.getField("PAYOR_OFFICE_CODE").getValue()));
                    }else {
                        session.setAttribute("MSG", labelMap.get(LabelMap.MSG_SAVE_FAIL));
                    }
                }else if (MODE == DBMgr.MODE_UPDATE) {
                    if (DBMgr.updateRecord(methodRec)) {
                        session.setAttribute("MSG", labelMap.get(LabelMap.MSG_SAVE_SUCCESS).replace("[HREF]", "input/method_alloc_payor_main.jsp?PAYOR_OFFICE_CODE=" + methodRec.getField("PAYOR_OFFICE_CODE").getValue()));
                    }else {
                        session.setAttribute("MSG", labelMap.get(LabelMap.MSG_SAVE_FAIL));
                    }
                }

                response.sendRedirect("../message.jsp");
                return;
            }
            else if (request.getParameter("ADMISSION_TYPE_CODE") != null && request.getParameter("PAYOR_OFFICE_CODE") != null) {
                // Edit
                MODE = DBMgr.MODE_UPDATE;
                //String sql = String.format("SELECT * FROM STP_METHOD_ALLOC_PAYOR WHERE HOSPITAL_CODE = '%1$s' AND PAYOR_OFFICE_CODE = '%2$s' AND ADMISSION_TYPE_CODE = '%3$s' AND IS_PRIVATE = '%4$s'", session.getAttribute("HOSPITAL_CODE"), request.getParameter("PAYOR_OFFICE_CODE"), request.getParameter("ADMISSION_TYPE_CODE"), request.getParameter("IS_PRIVATE"));
                methodRec = DBMgr.getRecord(String.format("SELECT * FROM STP_METHOD_ALLOC_PAYOR WHERE HOSPITAL_CODE = '%1$s' AND PAYOR_OFFICE_CODE = '%2$s' AND ADMISSION_TYPE_CODE = '%3$s' AND IS_PRIVATE = '%4$s' AND ORDER_ITEM_CODE = '%5$s' AND DOCTOR_CATEGORY_CODE = '%6$s'", session.getAttribute("HOSPITAL_CODE"), request.getParameter("PAYOR_OFFICE_CODE"), request.getParameter("ADMISSION_TYPE_CODE"), request.getParameter("IS_PRIVATE"), request.getParameter("ORDER_ITEM_CODE"), request.getParameter("DOCTOR_CATEGORY_CODE")));
                //out.println("sql = " + sql);
                doctorCategoryRec = DBMgr.getRecord(String.format("SELECT CODE, NAME_ENG FROM PAYOR_OFFICE WHERE CODE = '%1$s'", request.getParameter("PAYOR_OFFICE_CODE")));
                orderItemRec = DBMgr.getRecord(String.format("SELECT CODE,DESCRIPTION_ENG FROM ORDER_ITEM WHERE CODE = '%1$s'", request.getParameter("ORDER_ITEM_CODE")));
                orderItemCategoryRec = DBMgr.getRecord(String.format("SELECT CODE,DESCRIPTION_ENG FROM ORDER_ITEM_CATEGORY WHERE CODE = '%1$s'", request.getParameter("ORDER_ITEM_CATEGORY_CODE")));
                doctorCategoryDetailRec = DBMgr.getRecord(String.format("SELECT CODE,DESCRIPTION FROM DOCTOR_CATEGORY WHERE CODE = '%1$s'", request.getParameter("DOCTOR_CATEGORY_CODE")));
                }
            else if (request.getParameter("PAYOR_OFFICE_CODE") != null) {
                // New
                MODE = DBMgr.MODE_INSERT;
                doctorCategoryRec = DBMgr.getRecord(String.format("SELECT CODE, NAME_ENG FROM PAYOR_OFFICE WHERE CODE = '%1$s'", request.getParameter("PAYOR_OFFICE_CODE")));
            }
            /*else {
                response.sendRedirect("../message.jsp");
            }*/
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>${labelMap.TITLE_MAIN}</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="../../css/share.css" media="all" />
        <script type="text/javascript" src="../../javascript/ajax.js"></script>
        <script type="text/javascript" src="../../javascript/search_form.js"></script>
        <script type="text/javascript" src="../../javascript/util.js"></script>
        <script type="text/javascript">
            //DOCTOR_CATEGORY_CODE_KeyPress
            function PAYOR_OFFICE_CODE_KeyPress(e) {
                var key = window.event ? window.event.keyCode : e.which;    // ? IE : Firefox

                if (key == 13) {
                    document.mainForm.PAYOR_OFFICE_CODE.blur();
                    return false;
                }
                else {
                    return true;
                }
            }
			//AJAX_Refresh_DOCTOR_CATEGORY
            function AJAX_Refresh_PAYOR_DESCRIPTION() {
                var target = "../../RetrieveData?TABLE=PAYOR_OFFICE&COND=CODE='" + document.mainForm.PAYOR_OFFICE_CODE.value + "' AND HOSPITAL_CODE='<%=session.getAttribute("HOSPITAL_CODE")%>'";
                AJAX_Request(target, AJAX_Handle_Refresh_PAYOR_DESCRIPTION);
            }
            //AJAX_Handle_Refresh_DOCTOR_CATEGORY
            function AJAX_Handle_Refresh_PAYOR_DESCRIPTION() {
                if (AJAX_IsComplete()) {
                    var xmlDoc = AJAX.responseXML;

                    // Data not found
                    if (!isXMLNodeExist(xmlDoc, "CODE")) {
                        document.mainForm.PAYOR_OFFICE_CODE.value = "";
                        document.mainForm.PAYOR_OFFICE_DESCRIPTTION.value = "";
                        return;
                    }
                    
                    // Data found
                    document.mainForm.PAYOR_OFFICE_DESCRIPTTION.value = getXMLNodeValue(xmlDoc, "NAME_ENG");
                }
            }

            //Search Order ItemCode
            function ORDER_ITEM_CODE_KeyPress(e) {
                var key = window.event ? window.event.keyCode : e.which;    // ? IE : Firefox

                if (key == 13) {
                    document.mainForm.ORDER_ITEM_CODE.blur();
                    return false;
                }
                else {
                    return true;
                }
            }
			//AJAX_Refresh_ORDER_ITEM_DESCRIPTION
            function AJAX_Refresh_ORDER_ITEM_DESCRIPTION() {
                var target = "../../RetrieveData?TABLE=ORDER_ITEM&COND=CODE='" + document.mainForm.ORDER_ITEM_CODE.value + "' AND HOSPITAL_CODE='<%=session.getAttribute("HOSPITAL_CODE")%>'";
                AJAX_Request(target, AJAX_Handle_Refresh_ORDER_ITEM_DESCRIPTION);
            }
            //AJAX_Handle_Refresh_ORDER_ITEM_DESCRIPTION
            function AJAX_Handle_Refresh_ORDER_ITEM_DESCRIPTION() {
                if (AJAX_IsComplete()) {
                    var xmlDoc = AJAX.responseXML;

                    // Data not found
                    if (!isXMLNodeExist(xmlDoc, "CODE")) {
                        document.mainForm.ORDER_ITEM_CODE.value = "";
                        document.mainForm.ORDER_ITEM_DESCRIPTTION.value = "";
                        return;
                    }
                    
                    // Data found
                    document.mainForm.ORDER_ITEM_DESCRIPTTION.value = getXMLNodeValue(xmlDoc, "DESCRIPTION_ENG");
                }
            }
            //End Search Order ItemCode
            
            //Search Order Item Category Code
            function ORDER_ITEM_CATEGORY_CODE_KeyPress(e) {
                var key = window.event ? window.event.keyCode : e.which;    // ? IE : Firefox

                if (key == 13) {
                    document.mainForm.ORDER_ITEM_CATEGORY_CODE.blur();
                    return false;
                }
                else {
                    return true;
                }
            }
			//AJAX_Refresh_ORDER_ITEM_CATE_DESCRIPTION
            function AJAX_Refresh_ORDER_ITEM_CATE_DESCRIPTION() {
                var target = "../../RetrieveData?TABLE=ORDER_ITEM_CATEGORY&COND=CODE='" + document.mainForm.ORDER_ITEM_CATEGORY_CODE.value + "' AND HOSPITAL_CODE='<%=session.getAttribute("HOSPITAL_CODE")%>'";
                AJAX_Request(target, AJAX_Handle_Refresh_ORDER_ITEM_CATE_DESCRIPTION);
            }
            //AJAX_Handle_Refresh_ORDER_ITEM_DESCRIPTION
            function AJAX_Handle_Refresh_ORDER_ITEM_CATE_DESCRIPTION() {
                if (AJAX_IsComplete()) {
                    var xmlDoc = AJAX.responseXML;

                    // Data not found
                    if (!isXMLNodeExist(xmlDoc, "CODE")) {
                        document.mainForm.ORDER_ITEM_CATEGORY_CODE.value = "";
                        document.mainForm.ORDER_ITEM_CATE_DESCRIPTTION.value = "";
                        return;
                    }
                    
                    // Data found
                    document.mainForm.ORDER_ITEM_CATE_DESCRIPTTION.value = getXMLNodeValue(xmlDoc, "DESCRIPTION_ENG");
                }
            }
            //End Search Order Item Category Code
            
            //Search Doctor Category Code
            function DOCTOR_CATEGORY_CODE_KeyPress(e) {
                var key = window.event ? window.event.keyCode : e.which;    // ? IE : Firefox

                if (key == 13) {
                    document.mainForm.DOCTOR_CATEGORY_CODE.blur();
                    return false;
                }
                else {
                    return true;
                }
            }
			//AJAX_Refresh_DOCTOR_CATEGORY
            function AJAX_Refresh_DOCTOR_CATEGORY() {
                var target = "../../RetrieveData?TABLE=DOCTOR_CATEGORY&COND=CODE='" + document.mainForm.DOCTOR_CATEGORY_CODE.value + "' AND HOSPITAL_CODE='<%=session.getAttribute("HOSPITAL_CODE")%>'";
                AJAX_Request(target, AJAX_Handle_Refresh_DOCTOR_CATEGORY);
            }
            //AJAX_Handle_Refresh_DOCTOR_CATEGORY
            function AJAX_Handle_Refresh_DOCTOR_CATEGORY() {
                if (AJAX_IsComplete()) {
                    var xmlDoc = AJAX.responseXML;

                    // Data not found
                    if (!isXMLNodeExist(xmlDoc, "CODE")) {
                        document.mainForm.DOCTOR_CATEGORY_CODE.value = "";
                        document.mainForm.DOCTOR_CATEGORY_DESCRIPTTION.value = "";
                        return;
                    }
                    
                    // Data found
                    document.mainForm.DOCTOR_CATEGORY_DESCRIPTTION.value = getXMLNodeValue(xmlDoc, "DESCRIPTION");
                }
            }
            //End Search Doctor Category Code
            

            function AJAX_VerifyData() {
            	 var target = "../../RetrieveData?TABLE=STP_METHOD_ALLOC_PAYOR&COND=HOSPITAL_CODE='<%=session.getAttribute("HOSPITAL_CODE")%>' AND ADMISSION_TYPE_CODE='" + document.mainForm.ADMISSION_TYPE_CODE.value + 
            	 //"'AND NORMAL_ALLOCATE_PCT='" + document.mainForm.NORMAL_ALLOCATE_PCT.value + 
            	 //"'AND NORMAL_ALLOCATE_AMT='" + document.mainForm.NORMAL_ALLOCATE_AMT.value + 
            	 "'AND DOCTOR_TREATMENT_CODE='" + document.mainForm.DOCTOR_TREATMENT_CODE.value + 
            	 "'AND PAYOR_OFFICE_CODE='" + document.mainForm.PAYOR_OFFICE_CODE.value + 
            	 "'AND IS_PRIVATE='" + document.mainForm.IS_PRIVATE.value + 
            	 "'AND ORDER_ITEM_CODE='" + document.mainForm.ORDER_ITEM_CODE.value + 
            	 "'AND DOCTOR_CATEGORY_CODE='" + document.mainForm.DOCTOR_CATEGORY_CODE.value + "'";
                 AJAX_Request(target, AJAX_Handle_Verify_Data);
            }
            
            function AJAX_Handle_Verify_Data() {
                if (AJAX_IsComplete()) {
                    var xmlDoc = AJAX.responseXML;

                    var beExist = isXMLNodeExist(xmlDoc, "PAYOR_OFFICE_CODE");
                    
                    switch (document.mainForm.MODE.value) {
                        case "<%=DBMgr.MODE_INSERT%>" :
                            if (beExist) {
                                if (confirm("<%=labelMap.get("CONFIRM_REPLACE_DATA")%>")) {
                                    document.mainForm.MODE.value= "<%=DBMgr.MODE_UPDATE%>";
                                    document.mainForm.submit();
                                }
                            }
                            else {
                                document.mainForm.submit();
                            }
                            break;
                        case "<%=DBMgr.MODE_UPDATE%>" :
                            if (beExist) {
                                document.mainForm.submit();
                            }else {
                                if (confirm("<%=labelMap.get(LabelMap.CONFIRM_ADD_NEW_DATA)%>")) {
                                    document.mainForm.MODE.value= "<%=DBMgr.MODE_INSERT%>";
                                    document.mainForm.submit();
                                }
                            }
                            break;
                    }
                }
            }

            function SAVE_Click() {
               //if (!isObjectEmptyString(document.mainForm.PAYOR_OFFICE_CODE, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') && 
                    //!isObjectEmptyString(document.mainForm.ADMISSION_TYPE_CODE, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') && 
                    //isObjectValidNumber(document.mainForm.NORMAL_ALLOCATE_PCT, '<%=labelMap.get(LabelMap.ALERT_INVALID_NUMBER)%>') && 
                    //isObjectValidNumber(document.mainForm.NORMAL_ALLOCATE_AMT, '<%=labelMap.get(LabelMap.ALERT_INVALID_NUMBER)%>')) {
                    AJAX_VerifyData();
                //}
            }
            
        </script>
        <style type="text/css">
<!--
.style1 {color: #003399}
-->
        </style>
</head>
    <body>
        <form id="mainForm" name="mainForm" method="post" action="method_alloc_payor_detail.jsp">
            <input type="hidden" id="MODE" name="MODE" value="<%= MODE %>" />
            <table class="form" border="2">
                <tr>
                    <th colspan="4">
                        <div style="float: left;">${labelMap.TITLE_MAIN}</div>
                    </th>
                </tr>
                <tr>
                  <td class="label">
                    <label for="PAYOR_OFFICE_CODE"><span class="style1">${labelMap.PAYOR_OFFICE_CODE}*</span></label>                    </td>
                    <td class="input" colspan="3">
                        <input name="PAYOR_OFFICE_CODE" type="text" class="short" id="PAYOR_OFFICE_CODE" maxlength="20" readonly="readonly" value="<%= DBMgr.getRecordValue(doctorCategoryRec, "CODE")%>" onkeypress="return PAYOR_OFFICE_CODE_KeyPress(event);" onblur="AJAX_Handle_Refresh_PAYOR_DESCRIPTION()" />
                        <!-- <input type="image" class="image_button" src="../../images/search_button.png" alt="" onclick="openSearchForm('../search.jsp?TABLE=PAYOR_OFFICE&DISPLAY_FIELD=NAME_ENG&BEINSIDEHOSPITAL=1&BEACTIVE=1&TARGET=PAYOR_OFFICE_CODE&HANDLE=AJAX_Refresh_PAYOR_DESCRIPTION'); return false;" /> -->
                        <input name="PAYOR_OFFICE_DESCRIPTTION" type="text" class="mediumMax" id="PAYOR_OFFICE_DESCRIPTTION" readonly="readonly" value="<%= DBMgr.getRecordValue(doctorCategoryRec, "NAME_ENG")%>" maxlength="255" />                    
                    </td>
                </tr>
                <tr>
                  <td class="label">
                    <label for="DOCTOR_CATEGORY_CODE"><span class="style1">${labelMap.DOCTOR_CATEGORY_CODE}*</span></label>                    </td>
                    <td class="input" colspan="3">
                        <input name="DOCTOR_CATEGORY_CODE" type="text" class="short" id="DOCTOR_CATEGORY_CODE" maxlength="20" value="<%= DBMgr.getRecordValue(doctorCategoryDetailRec, "CODE")%>" onkeypress="return ORDER_ITEM_CATEGORY_CODE_KeyPress(event);" onblur="AJAX_Handle_Refresh_DOCTOR_CATEGORY_DESCRIPTION()" />
                        <input type="image" class="image_button" src="../../images/search_button.png" alt="" onclick="openSearchForm('../search.jsp?TABLE=DOCTOR_CATEGORY&DISPLAY_FIELD=DESCRIPTION&BEINSIDEHOSPITAL=1&BEACTIVE=1&TARGET=DOCTOR_CATEGORY_CODE&HANDLE=AJAX_Refresh_DOCTOR_CATEGORY'); return false;" />
                        <input name="DOCTOR_CATEGORY_DESCRIPTTION" type="text" class="mediumMax" id="DOCTOR_CATEGORY_DESCRIPTTION" readonly="readonly" value="<%= DBMgr.getRecordValue(doctorCategoryDetailRec, "DESCRIPTION")%>" maxlength="255" />                    
                    </td>
                </tr>
                <tr>
                  <td class="label">
                    <label for="ORDER_ITEM_CODE"><span class="">${labelMap.ORDER_ITEM_CODE}</span></label></td>
                    <td class="input" colspan="3">
                        <input name="ORDER_ITEM_CODE" type="text" class="short" id="ORDER_ITEM_CODE" maxlength="20" value="<%= DBMgr.getRecordValue(orderItemRec, "CODE")%>" onkeypress="return ORDER_ITEM_CODE_KeyPress(event);" onblur="AJAX_Handle_Refresh_ORDER_ITEM_DESCRIPTION()" />
                        <input type="image" class="image_button" src="../../images/search_button.png" alt="" onclick="openSearchForm('../search.jsp?TABLE=ORDER_ITEM&DISPLAY_FIELD=DESCRIPTION_ENG&BEINSIDEHOSPITAL=1&BEACTIVE=1&TARGET=ORDER_ITEM_CODE&HANDLE=AJAX_Refresh_ORDER_ITEM_DESCRIPTION'); return false;" />
                        <input name="ORDER_ITEM_DESCRIPTTION" type="text" class="mediumMax" id="ORDER_ITEM_DESCRIPTTION" readonly="readonly" value="<%= DBMgr.getRecordValue(orderItemRec, "DESCRIPTION_ENG")%>" maxlength="255" />                    
                    </td>
                </tr>
                <tr>
                  <td class="label">
                    <label for="ORDER_ITEM_CATEGORY_CODE"><span class="">${labelMap.ORDER_ITEM_CATEGORY_CODE}</span></label></td>
                    <td class="input" colspan="3">
                        <input name="ORDER_ITEM_CATEGORY_CODE" type="text" class="short" id="ORDER_ITEM_CATEGORY_CODE" maxlength="20" value="<%= DBMgr.getRecordValue(orderItemCategoryRec, "CODE")%>" onkeypress="return ORDER_ITEM_CATEGORY_CODE_KeyPress(event);" onblur="AJAX_Handle_Refresh_ORDER_ITEM_CATE_DESCRIPTION()" />
                        <input type="image" class="image_button" src="../../images/search_button.png" alt="" onclick="openSearchForm('../search.jsp?TABLE=ORDER_ITEM_CATEGORY&DISPLAY_FIELD=DESCRIPTION_ENG&BEINSIDEHOSPITAL=1&BEACTIVE=1&TARGET=ORDER_ITEM_CATEGORY_CODE&HANDLE=AJAX_Refresh_ORDER_ITEM_CATE_DESCRIPTION'); return false;" />
                        <input name="ORDER_ITEM_CATE_DESCRIPTTION" type="text" class="mediumMax" id="ORDER_ITEM_CATE_DESCRIPTTION" readonly="readonly" value="<%= DBMgr.getRecordValue(orderItemCategoryRec, "DESCRIPTION_ENG")%>" maxlength="255" />                    
                    </td>
                </tr>
                <tr>
                    <td class="label"><label for="ADMISSION_TYPE_CODE"><span class="style1">${labelMap.ADMISSION_TYPE_CODE}*</span></label></td>
                    <td colspan="" class="input">
                        <%= DBMgr.generateDropDownList("ADMISSION_TYPE_CODE", "medium", "inActive", "SELECT CODE, DESCRIPTION, ACTIVE FROM ADMISSION_TYPE ORDER BY DESCRIPTION", "DESCRIPTION", "CODE", DBMgr.getRecordValue(methodRec, "ADMISSION_TYPE_CODE")) %>
                    </td>
                    <td class="label"><label for="DOCTOR_TREATMENT_CODE"><span class="style1">${labelMap.DOCTOR_TREATMENT_CODE}*</span></label></td>
                    <td colspan="" class="input">
                        <%= DBMgr.generateDropDownList("DOCTOR_TREATMENT_CODE", "medium", "inActive", "SELECT CODE, DESCRIPTION, ACTIVE FROM DOCTOR_TREATMENT ORDER BY DESCRIPTION", "DESCRIPTION", "CODE", DBMgr.getRecordValue(methodRec, "DOCTOR_TREATMENT_CODE")) %>
                    </td>
                </tr>
                <tr>
                    <td class="label"><label for="IS_ALLOC_FULL_TAX">${labelMap.IS_ALLOC_FULL_TAX}*</label></td>
                    <td class="input">
                    	<select name="IS_ALLOC_FULL_TAX" class="" id="IS_ALLOC_FULL_TAX">
                    		<%if(MODE == DBMgr.MODE_INSERT){ %>
	                    		<option value="N" selected="selected">${labelMap.IS_ALLOC_FULL_TAX_0}</option>
	                    		<option value="Y">${labelMap.IS_ALLOC_FULL_TAX_1}</option>
                    		<%}else{%>
	                    		<option value="N" <%if(DBMgr.getRecordValue(methodRec, "IS_ALLOC_FULL_TAX").equals("N")){out.println("selected");}%>>${labelMap.IS_ALLOC_FULL_TAX_0}</option>
	                    		<option value="Y" <%if(DBMgr.getRecordValue(methodRec, "IS_ALLOC_FULL_TAX").equals("Y")){out.println("selected");}%>>${labelMap.IS_ALLOC_FULL_TAX_1}</option>
                    		<%} %>
                    	</select>
                    </td> 
                    <td class="label"><label for="TAX_RATE">${labelMap.TAX_RATE}*</label></td>
                    <td class="input">
                    	<select name="TAX_RATE" class="short" id="TAX_RATE">
                    		<%if(MODE == DBMgr.MODE_INSERT){ %>
	                    		<option value="1" selected="selected">${labelMap.TAX_RATE_0}</option>
	                    		<option value="1.1111">${labelMap.TAX_RATE_1}</option>
	                    		<option value="1.2500">${labelMap.TAX_RATE_2}</option>
                    		<%}else{%>
	                    		<option value="1" <%if(DBMgr.getRecordValue(methodRec, "TAX_RATE").equals("1.0000")){out.println("selected");}%>>${labelMap.TAX_RATE_0}</option>
	                    		<option value="1.1111" <%if(DBMgr.getRecordValue(methodRec, "TAX_RATE").equals("1.1111")){out.println("selected");}%>>${labelMap.TAX_RATE_1}</option>
	                    		<option value="1.2500" <%if(DBMgr.getRecordValue(methodRec, "TAX_RATE").equals("1.2500")){out.println("selected");}%>>${labelMap.TAX_RATE_2}</option>
	                    	<%} %>
                    	</select>
                    </td>
                </tr>
                <tr>
                    <td class="label"><label for="aText"><span class="style1">${labelMap.TAX_TYPE_CODE}*</span></label></td>
                    <td colspan="" class="input">
                        <%=DBMgr.generateDropDownList("TAX_TYPE_CODE", "medium", "inActive", "SELECT CODE, DESCRIPTION, ACTIVE FROM TAX_TYPE ORDER BY DESCRIPTION", "DESCRIPTION", "CODE", DBMgr.getRecordValue(methodRec, "TAX_TYPE_CODE"))%>
                    </td>
                    <td class="label"><label for="IS_PRIVATE">${labelMap.IS_PRIVATE}*</label></td>
                    <td class="input">
                    	<select name="IS_PRIVATE" class="short" id="IS_PRIVATE">
                    		<%if(MODE == DBMgr.MODE_INSERT){ %>
	                    		<option value="N" selected="selected">${labelMap.IS_PRIVATE_0}</option>
	                    		<option value="Y">${labelMap.IS_PRIVATE_1}</option>
                    		<%}else{%>
	                    		<option value="N" <%if(DBMgr.getRecordValue(methodRec, "IS_PRIVATE").equals("N")){out.println("selected");}%>>${labelMap.IS_PRIVATE_0}</option>
	                    		<option value="Y" <%if(DBMgr.getRecordValue(methodRec, "IS_PRIVATE").equals("Y")){out.println("selected");}%>>${labelMap.IS_PRIVATE_1}</option>
                    		<%} %>
                    	</select>
                    </td>
                </tr>
                <tr>
                    <td class="label"><label for="NORMAL_ALLOCATE_PCT">${labelMap.NORMAL_ALLOCATE_PCT}*</label></td>
                    <td class="input"><input type="text" id="NORMAL_ALLOCATE_PCT" name="NORMAL_ALLOCATE_PCT" class="short alignRight" value="<%= DBMgr.getRecordValue(methodRec, "NORMAL_ALLOCATE_PCT") %>" maxlength="13" />${labelMap.PERCENT}</td>
                    <td class="label"><label for="GUARANTEE_METHOD">${labelMap.GUARANTEE_METHOD}</label>                    </td>
                    <td colspan="" class="input">
					<select class="medium" id="GUARANTEE_METHOD" name="GUARANTEE_METHOD">
                        <option value="NONE"<%= DBMgr.getRecordValue(methodRec, "GUARANTEE_SOURCE").equalsIgnoreCase("NONE") ? " selected=\"selected\"" : "" %>>--- Undefined ---</option>
						<option value="DF"<%= DBMgr.getRecordValue(methodRec, "GUARANTEE_SOURCE").equalsIgnoreCase("DF") ? " selected=\"selected\"" : "" %>>${labelMap.GUARANTEE_SOURCE_AT}</option>
						<option value="FULL"<%= DBMgr.getRecordValue(methodRec, "GUARANTEE_SOURCE").equalsIgnoreCase("FULL") ? " selected=\"selected\"" : "" %>>${labelMap.GUARANTEE_SOURCE_BF}</option>
                    </select>
					</td>
                 </tr>  
                <tr>
                    <td class="label" colspan=""><label for="NORMAL_ALLOCATE_AMT">${labelMap.NORMAL_ALLOCATE_AMT}*</label></td>
                    <td class="input" colspan="3"><input type="text" id="NORMAL_ALLOCATE_AMT" name="NORMAL_ALLOCATE_AMT" class="short alignRight" value="<%= DBMgr.getRecordValue(methodRec, "NORMAL_ALLOCATE_AMT") %>" maxlength="13" />${labelMap.BAHT}</td>
                </tr>
                <tr>
                    <td class="label"><label for="REMARK">${labelMap.REMARK}</label></td>
                    <td colspan="3" class="input"><textarea id="REMARK" name="REMARK" class="long" rows="5"><%= DBMgr.getRecordValue(methodRec, "REMARK") %></textarea></td>
                </tr>
                <tr>
                    <td class="label"><label for="ACTIVE_1">${labelMap.ACTIVE}</label></td>
                    <td colspan="3" class="input">
                        <input type="radio" id="ACTIVE_1" name="ACTIVE" value="1"<%= DBMgr.getRecordValue(methodRec, "ACTIVE").equalsIgnoreCase("1") || DBMgr.getRecordValue(methodRec, "ACTIVE").equalsIgnoreCase("") ? " checked=\"checked\"" : ""%> />
                        <label for="ACTIVE_1">${labelMap.ACTIVE_1}</label>
                        <input type="radio" id="ACTIVE_0" name="ACTIVE" value="0"<%= DBMgr.getRecordValue(methodRec, "ACTIVE").equalsIgnoreCase("0") ? " checked=\"checked\"" : ""%> />
                        <label for="ACTIVE_0">${labelMap.ACTIVE_0}</label>
                    </td>
                </tr>
                <tr>
                    <th colspan="4" class="buttonBar">                        
                        <input type="button" id="SAVE" name="SAVE" class="button" value="${labelMap.SAVE}" onclick="SAVE_Click()" />
                        <input type="reset" id="RESET" name="RESET" class="button" value="${labelMap.RESET}" />
                        <input type="button" id="CLOSE" name="CLOSE" class="button" value="${labelMap.CLOSE}" onclick="window.location.href='method_alloc_payor_main.jsp?PAYOR_OFFICE_CODE=<%=request.getParameter("PAYOR_OFFICE_CODE")%>'" />
                    </th>
                </tr>
            </table>
        </form>
    </body>
</html>
